<?php
session_start();
if (!isset($_SESSION["admin_id"])) {
    header("Location: admin.php");
    exit;
}

require_once "includes/db.php"; // Veritabanı bağlantısı

// Kullanıcıları veritabanından çekme
$stmt = $conn->prepare("SELECT * FROM users");
$stmt->execute();
$users = $stmt->fetchAll();
?>

<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>Kullanıcı Yönetimi</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <h2>Kullanıcılar</h2>
    <table>
        <thead>
            <tr>
                <th>Kullanıcı Adı</th>
                <th>Şehir</th>
                <th>E-posta</th>
                <th>İşlem</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($users as $user): ?>
            <tr>
                <td><?= htmlspecialchars($user["username"]) ?></td>
                <td><?= htmlspecialchars($user["city"]) ?></td>
                <td><?= htmlspecialchars($user["email"]) ?></td>
                <td><a href="delete_user.php?user_id=<?= $user['id'] ?>">Sil</a></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
    <p><a href="admin_dashboard.php">Geri dön</a></p>
</body>
</html>
